import React from 'react';
import {useMount} from 'ahooks';
import {history} from 'umi';
import {Outlet} from 'umi';
import {useLocation} from '@@/exports';

const LoginGuard = () => {
    const userInfo = window.sessionStorage.getItem('userInfo');
    const menuLocation = useLocation();
    useMount(() => {
        if (userInfo) {
            history.push(menuLocation.pathname);
        } else {
            history.push('/login');
        }
    });
    return (
        <Outlet></Outlet>
    );
};
export default LoginGuard;
